package com.bw.cashier.page

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.bw.base.path.RouterPath
import com.bw.cashier.R
import com.bw.cashier.adapter.CashierAdapter
import com.bw.cashier.databinding.ActivityCashierBinding
import com.bw.cashier.vm.CashierViewModel
import com.bw.common.view.BaseMvvmActivity
import dagger.hilt.android.AndroidEntryPoint

/**
 * 收银台页面
 */
@Route(path = RouterPath.PATH_CASHIER_PATH)
@AndroidEntryPoint
class CashierActivity : BaseMvvmActivity<ActivityCashierBinding>() {
    private val mViewModel:CashierViewModel by viewModels()
    override fun getLayoutId(): Int =R.layout.activity_cashier
    val cAdapter = CashierAdapter()
    override fun initViews() {
        super.initViews()
        mDataBinding.back.setOnClickListener { finish() }
        mDataBinding.cashierRv.adapter =  cAdapter

        cAdapter.setOnItemClickListener { adapter, view, position ->
            ARouter.getInstance().build(RouterPath.PATH_CASHIER_DETAIL_PATH)
                .withInt("idc",cAdapter.data[position].id)
                .navigation()
        }


    }

    override fun loadData() {
        super.loadData()
        mViewModel.getCashierData(2)
    }

    override fun observeDataChanged() {
        super.observeDataChanged()
        mViewModel.mCashierSuccess.observe(this){
            cAdapter.setList(it)
            cAdapter.notifyDataSetChanged()
        }
    }
}